// DomUtils class. This class is used to perform dom operations. As this canvas library does not use any other third party library like
// jquery, we need a couple of dom manipulation functions to do by hand.
function DomUtils(){
	// gets the absolute position of an element - we need it to get the canvas position
	this.getOffset = function ( el ) {
		var _x = 0;
		var _y = 0;
		while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
			_x += el.offsetLeft - el.scrollLeft;
			_y += el.offsetTop - el.scrollTop;
			el = el.offsetParent;
		}
		return { top: _y, left: _x };
	}
	// more of a geometric function, says if 2 rectangles intersect - allows us to decide what shapes need redrawing
	this.boundariesIntersect = function(rect1, rect2){
		var minAx = rect1.x;
		var minAy = rect1.y;
		var maxAx = rect1.x+rect1.w;
		var maxAy = rect1.y+rect1.h;
		
		var minBx = rect2.x;
		var minBy = rect2.y;
		var maxBx = rect2.x+rect2.w;
		var maxBy = rect2.y+rect2.h;
		
		var aLeftOfB = maxAx < minBx;
		var aRightOfB = minAx > maxBx;
		var aAboveB = minAy > maxBy;
		var aBelowB = maxAy < minBy;

		return !( aLeftOfB || aRightOfB || aAboveB || aBelowB );
	},
	// add event cross browser
	// adds events to our canvas element
	this.addEventSimple = function (elem, event, fn) {
		if (elem.addEventListener) {
			elem.addEventListener(event, fn, false);
		} else {
        elem.attachEvent("on" + event, function() {
            // set the this pointer same as addEventListener when fn is called
            return(fn.call(elem, window.event));   
        });
    }
	this.cancelEvent = function(event) {
	   if (event.preventDefault) { 
		  event.preventDefault();
	   } else {
		  event.returnValue = false; 
	   }
	}
}
}